<?php
require_once(APPLICATION_PATH . '/../library/tcpdf/config/lang/eng.php');
require_once(APPLICATION_PATH . '/../library/tcpdf/tcpdf.php');

class App_Pdf extends TCPDF
{
    public $nomeRelatorio    = 'Nome do Relatório';
    public $nomeFormulario   = '000.000';
    public $departamento     = 'Presidência';
    public $versaoFormulario = '000';
    public $exibirLogo = true;

    public function preparar($departamento, $relatorio, $formulario, $versao)
    {
        $this->departamento     = $departamento;
        $this->nomeRelatorio    = $relatorio;
        $this->nomeFormulario   = $formulario;
        $this->versaoFormulario = $versao;

        // Metadata
        $this->SetAuthor('[CEV] Estrada Virtual');
        $this->SetTitle($relatorio);
        $this->SetSubject($relatorio);
        $this->SetKeywords('CEV, estrada virtual');

        // set header and footer fonts
        $this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

        // set default monospaced font
        $this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

        //set margins
        //$pdf->SetMargins(5, PDF_MARGIN_TOP, 5);
        $this->SetMargins(5, 20, 5, true);

        //set auto page breaks
        $this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

        //set image scale factor
        $this->setImageScale(PDF_IMAGE_SCALE_RATIO);

        //set some language-dependent strings
        //$this->setLanguageArray($l);
        $this->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');

        // set font
        $this->SetFont('times', '', 6);
    }

    public function header()
    {
        // Logo
        if ($this->exibirLogo) {
            $image_file = APPLICATION_PATH . '/../public/img/ev-logo.jpg';
            if ('L' == $this->CurOrientation) {
                $this->image($image_file, 23, 5, 30);
            } else {
                $this->image($image_file, 18, 5, 13, 13);
            }
        }

        // Set font
        $this->SetFont('helvetica', '', 9);
        if (80 < strlen($this->nomeRelatorio)) {
            $this->SetFont('helvetica', '', 6);
        }

        $Pageheader='
        <br><br>
        <table width="100%" border="1" cellpadding="0" cellspacing="0">
          <tr>
            <td width="18%" height="50px">&nbsp;</td>
            <td width="49%" align="center" valign="center">Gestão da Qualidade<br /><b>' . $this->nomeRelatorio . '</b></td>
            <td width="33%">
                <table border="0px" width="100%" height="100%">
                    <tr>
                        <td valign="center">' . $this->nomeFormulario . '</td>
                    </tr>
                    <tr>
                        <td valign="center">' . $this->departamento . '</td>
                    </tr>
                </table>
            </td>
          </tr>
        </table>';

        $this->writeHTML($Pageheader, false, false, false, false, '');
    } //fim header


    // Page footer
    public function Footer()
    {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('times', '', 9);
        $Pageheader='
        <br><br>
        <table width="100%" border="1" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="center">DOC.: ' . $this->nomeFormulario . '</td>
                <td valign="center">Versão: ' . $this->versaoFormulario . '</td>
                <td valign="center">Página: ' . $this->getAliasNumPage() . ' / ' . $this->getAliasNbPages() . '</td>
            </tr>
        </table>';
        $this->writeHTML($Pageheader, true, false, false, false, '');
    }
}
